package com.ibm.cps.message.validation;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.ibm.cps.message.MessageFields;
import com.ibm.util.ErrorCode;
import com.ibm.util.JSONUtility;
import com.ibm.util.exception.CPSException;

public abstract class IProcessorValidator {
	abstract public void validatePostMessage(ObjectNode object)
			throws CPSException;

	public String getProcessorid(ObjectNode object) throws CPSException {
		return getProcessorid(object, MessageFields.PROCESSORID);
	}

	String getProcessorid(ObjectNode object, String fieldName)
			throws CPSException {
		if (JSONUtility.isStringField(object, fieldName)) {
			return JSONUtility.GetString(fieldName, object, null);
		} else {
			throw new CPSException(ErrorCode.NULL_FIELD_ERROR,
					"Please provide the value of " + fieldName + " in "
							+ object.toString());
		}
	}

}
